package mess;

import java.util.Arrays;

public class LeeCode_88 {
    public static void main(String[] args) {
        int[] nums1 = new int[]{1,2,3,0,0,0};
        merge(nums1, 3, new int[]{2,5,6}, 3);
        int[] nums3 = new int[1];
        merge(nums3, 0, new int[]{1}, 1);
        System.out.println(Arrays.toString(nums3));
        //System.out.println(Arrays.toString(nums1));
//        System.out.println(Arrays.toString(nums1));
    }
    private static void merge(int[] nums1, int m, int[] nums2, int n) {
        int index1 = m - 1;
        int index = m + n - 1;
        int index2 = n - 1;
        while (index2 >= 0 && index1 >= 0){
            int num1 = nums1[index1];
            int num2 = nums2[index2];
            if (num1 >= num2){
                nums1[index] = num1;
                index--;
                index1--;
            }else {
                nums1[index] = num2;
                index--;
                index2--;
            }
        }
        if (index1 < 0) {
            for (; index2 >= 0; index2--)
                nums1[index2] = nums2[index2];
        }
    }
}
